const Router = require('koa-router')
const router = new Router()
const jwt = require('../libs/jwt')
const authenticate = jwt.authenticate()

const UserCtrl = require('../ctrls/user')
const LogsCtrl = require('../ctrls/logs')
const PlayerCtrl = require('../ctrls/player')
const ConfigCtrl = require('../ctrls/config')
const LabelCtrl = require('../ctrls/label')
router.get('/', ctx => {
  ctx.body = {
    version: 'v1.0',
    msg: '乐清花会游戏管理平台API',
    description: '专门承接棋牌app游戏项目开发，欢迎致电。'
  }
})

router.post('/login', UserCtrl.login)
router.post('/register', UserCtrl.register)

router.get('/user', authenticate)
router.get('/user/:uid?', UserCtrl.user)

router.get('/users', authenticate)
router.get('/users', UserCtrl.userList)

router.delete('/user', authenticate)
router.delete('/user/:uid?', UserCtrl.delete)

router.put('/user', authenticate)
router.put('/user', UserCtrl.update)

router.put('/user/reset', UserCtrl.reset)

router.put('/user/change', authenticate)
router.put('/user/change', UserCtrl.changeName)

router.get('/logs', authenticate)
router.get('/logs', LogsCtrl.logList)

router.delete('/log/delete', authenticate)
router.delete('/log/delete', LogsCtrl.delLog)

router.get('/player', authenticate)
router.get('/player', PlayerCtrl.playerList)

// 统计玩家信息
router.get('/player/statistic', authenticate)
router.get('/player/statistic', PlayerCtrl.statistic)

router.get('/player/:pid', authenticate)
router.get('/player/:pid', PlayerCtrl.playerInfo)

router.put('/player/freeze', authenticate)
router.put('/player/freeze', PlayerCtrl.freeze)

// 玩家上下分
router.put('/player/gold', authenticate)
router.put('/player/gold', PlayerCtrl.changeGold)



router.get('/config', ConfigCtrl.config)

router.put('/config/key', authenticate)
router.put('/config/key', ConfigCtrl.updateKey)

// router.put('/config', authenticate)
// router.put('/config', ConfigCtrl.updateConfig)

router.get('/label', authenticate)
router.get('/label', LabelCtrl.getLabel)
router.post('/label', LabelCtrl.setLabel)

module.exports = router
